GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 96.8% 90 / 0 / 93
Functions: 100.0% 8 / 0 / 8
Branches: 81.1% 60 / 0 / 74

src/NavigationAndEscapeCoordinator.cpp
Line Branch Exec Source
1 #include "rvc/NavigationAndEscapeCoordinator.hpp"
2
3 #include "rvc/SurfaceCleaningController.hpp"
4
5 namespace rvc {
6
7 30 NavigationAndEscapeCoordinator::NavigationAndEscapeCoordinator(MotionCommandSink& motionSink,
8 SurfaceCleaningController& cleaning)
9 30 : motionSink_(motionSink), cleaning_(cleaning) {}
10
11 24 void NavigationAndEscapeCoordinator::SessionStateChanged(bool active) {
12 24 sessionActive_ = active;
13
14
2/2
✓ Branch 2 → 3 taken 19 times.
✓ Branch 2 → 4 taken 5 times.
24 if (active) {
15 19 motionState_ = MotionState::ForwardCruise;
16 19 return;
17 }
18
19 5 motionState_ = MotionState::Stopped;
20 5 send(MotionCommand::stop);
21 }
22
23 34 void NavigationAndEscapeCoordinator::FusedObstacleSnapshot(const rvc::FusedObstacleSnapshot& snapshot) {
24
2/2
✓ Branch 2 → 3 taken 16 times.
✓ Branch 2 → 5 taken 18 times.
34 if (!sessionActive_) {
25 16 send(MotionCommand::suppressMotionTBD);
26 16 return;
27 }
28
29
3/4
✓ Branch 5 → 6 taken 18 times.
✗ Branch 5 → 8 not taken.
✓ Branch 6 → 7 taken 17 times.
✓ Branch 6 → 8 taken 1 time.
18 if (!snapshot.valid || snapshot.kind == FusedObstacleSnapshotKind::invalid ||
30
2/2
✓ Branch 7 → 8 taken 1 time.
✓ Branch 7 → 10 taken 16 times.
17 snapshot.kind == FusedObstacleSnapshotKind::partialStale) {
31 2 handleInvalidOrStale(snapshot);
32 2 return;
33 }
34
35
1/2
✓ Branch 10 → 11 taken 16 times.
✗ Branch 10 → 15 not taken.
16 if (snapshot.kind == FusedObstacleSnapshotKind::ambiguous ||
36
1/2
✓ Branch 11 → 12 taken 16 times.
✗ Branch 11 → 15 not taken.
16 snapshot.kind == FusedObstacleSnapshotKind::incoherent ||
37
2/2
✓ Branch 12 → 13 taken 15 times.
✓ Branch 12 → 15 taken 1 time.
16 snapshot.kind == FusedObstacleSnapshotKind::valid ||
38
2/2
✓ Branch 13 → 14 taken 14 times.
✓ Branch 13 → 15 taken 1 time.
15 snapshot.kind == FusedObstacleSnapshotKind::consistencyApplied ||
39
2/2
✓ Branch 14 → 15 taken 1 time.
✓ Branch 14 → 16 taken 13 times.
14 snapshot.kind == FusedObstacleSnapshotKind::alignedSnapshotTBD) {
40 3 return;
41 }
42
43
2/2
✓ Branch 16 → 17 taken 1 time.
✓ Branch 16 → 19 taken 12 times.
13 if (snapshot.kind == FusedObstacleSnapshotKind::unstable) {
44 1 send(MotionCommand::suppressMotionTBD);
45 1 return;
46 }
47
48
4/4
✓ Branch 19 → 20 taken 11 times.
✓ Branch 19 → 27 taken 1 time.
✓ Branch 20 → 21 taken 10 times.
✓ Branch 20 → 27 taken 1 time.
12 if (snapshot.surrounded || snapshot.kind == FusedObstacleSnapshotKind::surrounded ||
49
2/2
✓ Branch 21 → 22 taken 9 times.
✓ Branch 21 → 27 taken 1 time.
10 snapshot.kind == FusedObstacleSnapshotKind::noLateralOpening ||
50
2/2
✓ Branch 22 → 23 taken 8 times.
✓ Branch 22 → 27 taken 1 time.
9 snapshot.kind == FusedObstacleSnapshotKind::reverseReadings ||
51
1/2
✓ Branch 23 → 24 taken 8 times.
✗ Branch 23 → 27 not taken.
8 snapshot.kind == FusedObstacleSnapshotKind::reverseCycleSample ||
52
1/2
✓ Branch 24 → 25 taken 8 times.
✗ Branch 24 → 27 not taken.
8 snapshot.kind == FusedObstacleSnapshotKind::lateralOpening ||
53
2/2
✓ Branch 25 → 26 taken 7 times.
✓ Branch 25 → 27 taken 1 time.
8 snapshot.kind == FusedObstacleSnapshotKind::rightTurnViable ||
54
2/2
✓ Branch 26 → 27 taken 1 time.
✓ Branch 26 → 29 taken 6 times.
7 snapshot.kind == FusedObstacleSnapshotKind::leftTurnViable) {
55 6 handleSurrounded(snapshot);
56 6 return;
57 }
58
59
3/4
✓ Branch 29 → 30 taken 5 times.
✓ Branch 29 → 33 taken 1 time.
✓ Branch 30 → 31 taken 5 times.
✗ Branch 30 → 33 not taken.
6 if (snapshot.forwardBlocked || snapshot.kind == FusedObstacleSnapshotKind::forwardBlocked ||
60
1/2
✓ Branch 31 → 32 taken 5 times.
✗ Branch 31 → 33 not taken.
5 snapshot.kind == FusedObstacleSnapshotKind::notSurrounded ||
61
2/2
✓ Branch 32 → 33 taken 1 time.
✓ Branch 32 → 35 taken 4 times.
5 snapshot.kind == FusedObstacleSnapshotKind::rightTurnInvalid) {
62 2 handleForwardBlocked(snapshot);
63 2 return;
64 }
65
66
3/4
✓ Branch 35 → 36 taken 3 times.
✓ Branch 35 → 37 taken 1 time.
✓ Branch 36 → 37 taken 3 times.
✗ Branch 36 → 39 not taken.
4 if (snapshot.forwardSafe || snapshot.kind == FusedObstacleSnapshotKind::forwardSafe) {
67 4 handleForwardSafe();
68 4 return;
69 }
70
71 send(MotionCommand::probeOrBackupTBD);
72 }
73
74 38 void NavigationAndEscapeCoordinator::send(MotionCommand command) {
75 38 motionSink_.MotionCommand(command);
76 38 }
77
78 2 void NavigationAndEscapeCoordinator::handleInvalidOrStale(const rvc::FusedObstacleSnapshot& snapshot) {
79 2 motionState_ = MotionState::Stopped;
80
81
2/2
✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 5 taken 1 time.
2 if (snapshot.kind == FusedObstacleSnapshotKind::partialStale) {
82 1 send(MotionCommand::gradualOrPartialStopTBD);
83 1 return;
84 }
85
86 1 send(MotionCommand::stop);
87 1 cleaning_.SuspendCleaningForManeuver();
88 }
89
90 6 void NavigationAndEscapeCoordinator::handleSurrounded(const rvc::FusedObstacleSnapshot& snapshot) {
91
2/2
✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 7 taken 4 times.
6 if (snapshot.kind == FusedObstacleSnapshotKind::surrounded) {
92 2 motionState_ = MotionState::Reversing;
93 2 backupDistanceRemaining_ = 1.0;
94 2 send(MotionCommand::forbidForward);
95 2 send(MotionCommand::reverse);
96 2 cleaning_.SuspendCleaningForManeuver();
97 2 return;
98 }
99
100
2/2
✓ Branch 7 → 8 taken 3 times.
✓ Branch 7 → 9 taken 1 time.
4 if (snapshot.kind == FusedObstacleSnapshotKind::reverseReadings ||
101
1/2
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 11 taken 3 times.
3 snapshot.kind == FusedObstacleSnapshotKind::reverseCycleSample) {
102 1 motionState_ = MotionState::Reversing;
103 1 send(MotionCommand::continueReverse);
104 1 return;
105 }
106
107
3/4
✓ Branch 11 → 12 taken 2 times.
✓ Branch 11 → 13 taken 1 time.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 15 taken 2 times.
3 if (snapshot.kind == FusedObstacleSnapshotKind::rightTurnViable || snapshot.rightTurnViable) {
108 1 motionState_ = MotionState::Turning;
109 1 send(MotionCommand::lateralEscapeRight);
110 1 return;
111 }
112
113
3/4
✓ Branch 15 → 16 taken 1 time.
✓ Branch 15 → 17 taken 1 time.
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 19 taken 1 time.
2 if (snapshot.kind == FusedObstacleSnapshotKind::leftTurnViable || snapshot.leftTurnViable) {
114 1 motionState_ = MotionState::Turning;
115 1 send(MotionCommand::lateralEscapeLeft);
116 1 return;
117 }
118
119
1/2
✓ Branch 19 → 20 taken 1 time.
✗ Branch 19 → 22 not taken.
1 if (snapshot.kind == FusedObstacleSnapshotKind::noLateralOpening) {
120 1 send(MotionCommand::fallbackTBD);
121 1 return;
122 }
123
124 send(MotionCommand::probeOrBackupTBD);
125 }
126
127 2 void NavigationAndEscapeCoordinator::handleForwardBlocked(const rvc::FusedObstacleSnapshot& snapshot) {
128 2 motionState_ = MotionState::Avoiding;
129 2 cleaning_.SuspendCleaningForManeuver();
130
131
3/4
✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 5 taken 1 time.
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 1 time.
2 if (snapshot.kind == FusedObstacleSnapshotKind::rightTurnInvalid || snapshot.leftTurnViable) {
132 1 send(MotionCommand::turnLeft);
133
1/2
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 8 not taken.
1 } else if (snapshot.rightTurnViable) {
134 1 send(MotionCommand::turnRight);
135 } else {
136 send(MotionCommand::probeOrBackupTBD);
137 }
138 2 }
139
140 4 void NavigationAndEscapeCoordinator::handleForwardSafe() {
141 4 motionState_ = MotionState::ForwardCruise;
142 4 send(MotionCommand::forward);
143 4 cleaning_.ResumeCleaningAfterManeuver();
144 4 }
145
146 } // namespace rvc
147